package com.yuan.spring.reflect;

import org.junit.Test;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;

import java.lang.reflect.Method;

public class ReflectRest {
    private static final LocalVariableTableParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();


    @Test
    public void mainTest() throws ClassNotFoundException {
        Method[] methods = User.class.getMethods();
        StringBuilder sb = new StringBuilder();
        for (Method method : methods) {
            sb.append("方法：" + method.getName() + " ");
            String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);
            if (parameterNames == null || parameterNames.length < 1) {
                sb.append("无参");
            } else {
                sb.append("[");
                for (int i = 0; i < parameterNames.length; i++) {
                    sb.append(parameterNames[i]);
                    sb.append(",");
                }
                sb.append("]");
            }
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
}
